package com.zdj.math;

import org.junit.Test;
import org.springframework.util.Assert;

import java.math.BigDecimal;

/**
 * @author zhangdj
 * @date 2022-08-09
 */
public class Main {

    @Test
    public void round() {
        System.out.println(this.getScoreByTestCaseCount(4, 7, new BigDecimal(10)));
    }

    private BigDecimal getScoreByTestCaseCount(int pass, int total, BigDecimal totalScore) {
        if (total == 0) {
            return new BigDecimal(0);
        }
        Assert.isTrue(total >= pass, "用例数量错误");
        // 通过率
        BigDecimal passRate = BigDecimal.valueOf((float) pass / total);
        return passRate.setScale(1, BigDecimal.ROUND_HALF_UP).multiply(totalScore);
    }
}
